package
{
	
	
	import com.flashdynamix.utils.SWFProfiler;
	import com.greensock.plugins.TintPlugin;
	import com.greensock.plugins.TweenPlugin;
	
	import controller.EventController;
	
	import flash.display.MovieClip;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.MouseEvent;
	
	import model.ModelLocator;
	import model.Service;
	
	import mx.controls.Alert;
	import mx.core.Application;
	
	import subumbo.audio.core.AudioEngine;
	import subumbo.audio.core.Mixer;
	import subumbo.audio.effect.Freeverb;
	import subumbo.audio.generator.Turntable;
	
	import view.main.Menu;



	public class MainController extends Application
	{
		protected var _audio:AudioEngine
		private var _eventController:EventController;
		private var _services:Service;
		[Bindable] protected var _model:ModelLocator;
		private var _menu:Menu;
		
		public function MainController()
		{
			super();
		}
		
		protected function init():void
		{
			_model = ModelLocator.Instance;
			_audio = AudioEngine.instance;
			var mixer:Mixer = _audio.mixer;
			_audio.addGenerator(new Turntable("banda","Banda.mp3"));
			//_audio.addEffect(new Freeverb());
			//setTimeout(startup, 200);	
		}
		
		private function handleRightClick(e:MouseEvent):void
		{
			Alert.show();
			_menu.visible = true;
			this.addChild(_menu)
		}
		
		protected function startup():void
		{
			
			// DEBUGGER
			//ExternalInterface.addCallback("rightClick", handleRightClick);
			//Application.application.addEventListener(MouseEvent.DOUBLE_CLICK, handleRightClick);
			

			
			SWFProfiler.init(systemManager.stage,this);
			
			TweenPlugin.activate([TintPlugin]);
			
			systemManager.stage.scaleMode = StageScaleMode.NO_SCALE;
			systemManager.stage.align = StageAlign.TOP_LEFT;
			_eventController = new EventController();
			_services = new Service();
			
			//_audio = AudioEngine.instance;
			//_audio.addGenerator(new Turntable("banda.mp3"), "banda");
			//_audio.addEffect(new Freeverb(0.5, .5));
			//_audio.addEffect(new SimpleDelay(500 * 44.1, .2, 1));
			//setTimeout(_audio.driver.play, 10);	
			//new ApplicationEvent(ApplicationEvent.GET_DATA).dispatch();
		}
		
		public function get mixer():Mixer
		{
			return _audio.mixer;
		}
		
		protected function render(vin:MovieClip):void
		{
			vin.rotation += 2;
		}
	}
}